package projetolp2.GraphicInterface;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.List;

import javax.swing.AbstractListModel;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import projetolp2.Sistem.Estabelecimento;
import projetolp2.Sistem.Sistema;

public class SugestoesGenerica extends MealPoints implements ActionListener{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private JPanel panelMenu = new JPanel(new BorderLayout());
	private JPanel panel1 = new JPanel(new GridLayout(0, 1));
	private JPanel panel2 = new JPanel(new GridLayout(0, 1));
	private JButton VOLTAR = new JButton(NomeBotoes.values()[idioma(IDIOMAPROGRAMA )].getVoltar());
	private JLabel label;
	private int quantidade = 0;
	public SugestoesGenerica(){
		
	}
	private void ajudaDeBotoes(){
		VOLTAR.setToolTipText("Voltar a janela anterior");
	}
	
	public void actionPerformed(ActionEvent e){
		if(e.getSource() == VOLTAR){
			removerAdicionar(((SugestoesGenerica) sugestoesGenerica).panel(),sugestoes );
			
		}
	}
	public void quantidade(int valor){
		quantidade = valor;
	}
	@SuppressWarnings("serial")
	private void createComponents() {
		//quantidadeSugestoes.pegaQuant();
		panelMenu.removeAll();
		panel1.removeAll();
		panel2.removeAll();
		ajudaDeBotoes();
		label = new JLabel("Os "+quantidade+" melhores restaurantes");
		
		 JList texto = new JList();
         String estabelecimentos = "Nome            -           Endereço;;;;********;";
         
         List<Estabelecimento> recomendacao = SISTEMA.recomendacao(quantidade); //modificado 10/06 (Dig)
         List<String> saida = SISTEMA.converteEstabelecimentos(recomendacao);
         
		 for (String i : saida){
			 estabelecimentos += i+";------------------------------------------------------------------;";
		 }
         
	        try{
	        	final String valorees = estabelecimentos;
	        texto.setModel(new AbstractListModel() {
	        	String[] valores = valorees.split(";");
	            public int getSize() { return valores.length; }
	            public Object getElementAt(int i) { return valores[i]; }
	        });

	        texto.setName("jList1"); // NOI18N
	        }catch(Exception e){
	        	System.err.println(e.getMessage());
	        }
	    
		VOLTAR.setMnemonic(KeyEvent.VK_I);
		VOLTAR.addActionListener(this);
        label.setLabelFor(VOLTAR);
		
        panel1.add(new JScrollPane(texto));
        panel1.setBorder(BorderFactory.createEmptyBorder(
                10, //top
                10, //left
                10, //bottom
                10) //right
                );
        panel2.add(VOLTAR);
        panel2.setBorder(BorderFactory.createEmptyBorder(
                10, //top
                300, //left
                10, //bottom
                60) //right
                );
        panelMenu.add(panel1);
        panelMenu.add(panel2,BorderLayout.SOUTH);
       
    }
	public Component panel(){
		createComponents();
		panelMenu.setVisible(true);
		
		
		return panelMenu;
	}

}

